#ifndef _GATE_SESSION_BASE_H_
#define _GATE_SESSION_BASE_H_

#include "SessionBase.h"
#include <string>
#include <vector>

// 所有使用gate的服务器继承这个定义,如各游戏服
class CGateSessionBase : public CSessionBase
{
public:
    CGateSessionBase(s32 id);
    virtual ~CGateSessionBase();
    
    virtual SGLib::CIoSocketEx* Clone(s32 id);
	void GetGateState(s32 &curConn, s32 &maxConn, std::string &ip, s32 &port);

	void SendMsgToGate(u32 msgid, const IMessage &msg);
	void SendMsgToClients(s32 count, u64 *clients, u32 msgid, const IMessage &msg);
	void SendMsgToClient(u64 clientid, u32 msgid, const IMessage &msg);
	void SendMsgToClients(std::vector<u64> &sessions, u32 msgid, const IMessage &msg);

	const std::string& GetIp();
	s32 GetPort();

protected:
	virtual void _OnMessage(u32 msgid, const byte *msg, s32 len);

protected:
	// 需要实现下面的接口
	virtual void _OnOtherMessage(u64 gateid, u64 clientid, u32 msgid, const byte *msg, s32 len){}
    virtual void _OnClientClose(u64 gateid, u64 clientid);
    
private:
	void _OnClientClose(const byte *pkg, s32 len);
	void _OnForwardClientMsg(const byte *pkg, s32 len);
	void _OnGateReportStatus(const byte *pkg, s32 len);
	void _OnClientMessage(u64 gateid, u64 clientid, u32 msgid, const byte *msg, s32 len, u32 remoteip);

protected:
	s32	m_curConn;
	s32	m_maxConn;
	std::string	m_ip;
	s32	m_port;
};

#endif

